/**
 * @author Angel Marcos Sosa León.
 */
package uoc.ei.practica;
/**
 * Clase que representa una entitad ficha en el sistema
 */
public class Board

{
	
	/**
	 * Tablero para almacenar las fichas jugadas
	 */
	private char tableroChar[][];
	
	
	
	/**
	 * tablero de la partida. No se usa variable static final, para poder resetearlo en cada
	 * nueva partida
	 */
	private int[][] tablero = {
			{0,0,4,0,2,0,0,0,0,0,2,0,4,0,0},
			{0,2,0,0,0,3,0,0,0,3,0,0,0,2,0},
			{4,0,1,0,0,0,2,0,2,0,0,0,1,0,4},
			{0,0,0,2,0,0,0,1,0,0,0,2,0,0,0},
			{2,0,0,0,0,0,1,0,1,0,0,0,0,0,2},
			{0,3,0,0,0,2,0,0,0,2,0,0,0,3,0},
			{0,0,2,0,1,0,0,0,0,0,1,0,2,0,0},
			{0,0,0,3,0,0,0,0,0,0,0,3,0,0,0},
			{0,0,2,0,1,0,0,0,0,0,1,0,2,0,0},
			{0,3,0,0,0,2,0,0,0,2,0,0,0,3,0},
			{2,0,0,0,0,0,1,0,1,0,0,0,0,0,2},
			{0,0,0,2,0,0,0,3,0,0,0,2,0,0,0},
			{4,0,1,0,0,0,2,0,2,0,0,0,1,0,4},
			{0,2,0,0,0,3,0,0,0,3,0,0,0,2,0},
			{0,0,4,0,2,0,0,0,0,0,2,0,4,0,0}
	};

	
	public Board() 
	{
		
		this.tableroChar=new char[15][15];		
	}


	/**
	 * Carga la letra de una ficha jugada en la posicion del 
	 * tablero de caracteres y actualiza el tablero de enteros para
	 * luego imprimir correctamente por pantalla
	 */
	
	public int loadChar(int row, int column,char c)
	{
		int sw=0;
		tableroChar[row][column]=c;
		sw=tablero[row][column];
		if (sw==5)sw=0;
		sw=sw+5;		
		if (sw>5)tablero[row][column]=6;
		else tablero[row][column]=5;
		return sw;
	}
		
	public String toString()
	{
	
		StringBuffer sb=new StringBuffer();
		for(int row = 0; row < tablero.length; row++)
		{
			for(int column = 0; column < tablero[0].length; column++)
			{
				
				switch (tablero[row][column])
				{
				
					case 0: sb.append("    ");
					break;
					case 1: sb.append("[DL]");
					break;
					case 2: sb.append("[TL]");
					break;
					case 3: sb.append("[DP]");
					break;
					case 4: sb.append("[TP]");
					break;
					case 5: sb.append(" "+tableroChar[row][column]+"  ");
					break;
					case 6: sb.append(" "+tableroChar[row][column]+"+ ");
					break;
				}			
				
			}
			sb.append(Messages.LS);
		}
		return sb.toString();
	}
	
}
